import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';
import type { FactoryBase, FactoryBaseId } from './FactoryBase';
import type { FactoryToyManual, FactoryToyManualId } from './FactoryToyManual';
import type { UserToyItem, UserToyItemId } from './UserToyItem';

export interface FactoryToyItemAttributes {
  id: string;
  factoryId: string;
  name: string;
  type?: string;
  createdTime: Date;
  updatedTime: Date;
}

export type FactoryToyItemPk = 'id';
export type FactoryToyItemId = FactoryToyItem[FactoryToyItemPk];
export type FactoryToyItemOptionalAttributes =
  | 'type'
  | 'createdTime'
  | 'updatedTime';
export type FactoryToyItemCreationAttributes = Optional<
  FactoryToyItemAttributes,
  FactoryToyItemOptionalAttributes
>;

export class FactoryToyItem
  extends Model<FactoryToyItemAttributes, FactoryToyItemCreationAttributes>
  implements FactoryToyItemAttributes
{
  id!: string;
  factoryId!: string;
  name!: string;
  type?: string;
  createdTime!: Date;
  updatedTime!: Date;

  // FactoryToyItem belongsTo FactoryBase via factoryId
  factory!: FactoryBase;
  getFactory!: Sequelize.BelongsToGetAssociationMixin<FactoryBase>;
  setFactory!: Sequelize.BelongsToSetAssociationMixin<
    FactoryBase,
    FactoryBaseId
  >;
  createFactory!: Sequelize.BelongsToCreateAssociationMixin<FactoryBase>;
  // FactoryToyItem hasMany FactoryToyManual via toyId
  factoryToyManuals!: FactoryToyManual[];
  getFactoryToyManuals!: Sequelize.HasManyGetAssociationsMixin<FactoryToyManual>;
  setFactoryToyManuals!: Sequelize.HasManySetAssociationsMixin<
    FactoryToyManual,
    FactoryToyManualId
  >;
  addFactoryToyManual!: Sequelize.HasManyAddAssociationMixin<
    FactoryToyManual,
    FactoryToyManualId
  >;
  addFactoryToyManuals!: Sequelize.HasManyAddAssociationsMixin<
    FactoryToyManual,
    FactoryToyManualId
  >;
  createFactoryToyManual!: Sequelize.HasManyCreateAssociationMixin<FactoryToyManual>;
  removeFactoryToyManual!: Sequelize.HasManyRemoveAssociationMixin<
    FactoryToyManual,
    FactoryToyManualId
  >;
  removeFactoryToyManuals!: Sequelize.HasManyRemoveAssociationsMixin<
    FactoryToyManual,
    FactoryToyManualId
  >;
  hasFactoryToyManual!: Sequelize.HasManyHasAssociationMixin<
    FactoryToyManual,
    FactoryToyManualId
  >;
  hasFactoryToyManuals!: Sequelize.HasManyHasAssociationsMixin<
    FactoryToyManual,
    FactoryToyManualId
  >;
  countFactoryToyManuals!: Sequelize.HasManyCountAssociationsMixin;
  // FactoryToyItem hasMany UserToyItem via toyId
  userToyItems!: UserToyItem[];
  getUserToyItems!: Sequelize.HasManyGetAssociationsMixin<UserToyItem>;
  setUserToyItems!: Sequelize.HasManySetAssociationsMixin<
    UserToyItem,
    UserToyItemId
  >;
  addUserToyItem!: Sequelize.HasManyAddAssociationMixin<
    UserToyItem,
    UserToyItemId
  >;
  addUserToyItems!: Sequelize.HasManyAddAssociationsMixin<
    UserToyItem,
    UserToyItemId
  >;
  createUserToyItem!: Sequelize.HasManyCreateAssociationMixin<UserToyItem>;
  removeUserToyItem!: Sequelize.HasManyRemoveAssociationMixin<
    UserToyItem,
    UserToyItemId
  >;
  removeUserToyItems!: Sequelize.HasManyRemoveAssociationsMixin<
    UserToyItem,
    UserToyItemId
  >;
  hasUserToyItem!: Sequelize.HasManyHasAssociationMixin<
    UserToyItem,
    UserToyItemId
  >;
  hasUserToyItems!: Sequelize.HasManyHasAssociationsMixin<
    UserToyItem,
    UserToyItemId
  >;
  countUserToyItems!: Sequelize.HasManyCountAssociationsMixin;

  static initModel(sequelize: Sequelize.Sequelize): typeof FactoryToyItem {
    return FactoryToyItem.init(
      {
        id: {
          type: DataTypes.CHAR(36),
          allowNull: false,
          primaryKey: true,
          comment: '雪花主键',
        },
        factoryId: {
          type: DataTypes.CHAR(36),
          allowNull: false,
          comment: '所属工厂ID',
          references: {
            model: 'factory_base',
            key: 'id',
          },
          field: 'factory_id',
        },
        name: {
          type: DataTypes.STRING(255),
          allowNull: false,
          comment: '玩具名字',
        },
        type: {
          type: DataTypes.STRING(50),
          allowNull: true,
          comment: '玩具类型',
        },
        createdTime: {
          type: DataTypes.DATE,
          allowNull: false,
          defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
          comment: '创建时间',
          field: 'created_time',
        },
        updatedTime: {
          type: DataTypes.DATE,
          allowNull: false,
          defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
          comment: '更新时间',
          field: 'updated_time',
        },
      },
      {
        sequelize,
        tableName: 'factory_toy_item',
        timestamps: false,
        indexes: [
          {
            name: 'PRIMARY',
            unique: true,
            using: 'BTREE',
            fields: [{ name: 'id' }],
          },
          {
            name: 'idx_factory_toy_item',
            using: 'BTREE',
            fields: [{ name: 'id' }],
          },
          {
            name: 'fk_factory_toy_item',
            using: 'BTREE',
            fields: [{ name: 'factory_id' }],
          },
        ],
      },
    );
  }
}
